<?php
namespace Weibo\Model;
use Common\Model\BaseModel;
class WeiboAttachmentModel extends BaseModel {
	
	public function _initialize() {
		$this -> option['cache'] = FALSE;	//启用redis缓存前这张表不能启用缓存,因为资源服务器的文件缓存与主服务器的无法同步刷新
	}
	
	/**
	 * 获取用户的微博相册
	 * @author	Baiyu
	 * @param	number	$user_id	用户ID
	 * @param	number	$limit		最多取几条数据
	 * @param	string	$time		时间区间,类似于获取微博列表的时间区间,方便用于下拉刷新和上拉刷旧
	 * @param	number	$deleted	0为正常状态1为已删除2为作者删除3为系统删除4为举报删除all为全部
	 * @return	array|boolean
	 */
	public function getUserPictures($user_id, $limit = 10, $time = '', $deleted = 0) {
		
		$where = array(
			'user_id' => $user_id,
		);
		
		is_numeric($deleted) && $where['deleted'] = $deleted;
		
		//按时间区间取
		if ($time) {
			if (strpos($time, ',') !== FALSE) {
				list($time_begin, $time_end) = explode(',', $time);
			} else {
				$time_begin = $time;
			}
				
			empty($time_end) && $time_end = NOW_TIME;
			$where['create_time'] = array('BETWEEN', intval($time_begin).' AND '.intval($time_end));
		}
		
		return $this -> where($where) -> order(array('create_time' => 'DESC')) ->  limit(0, 10) -> select();
	}
	
}
